package com.zelic.zwrite;

public class Util {
	public static double[] DoubleBinaryTargetArray(int position, int size) {
        double[] result = new double[size];
        for (int i = 0; i < size; i++) {
            result[i] = 0;
        }
        result[position] = 1;
        return result;
    }

    public static double[] DoubleBipolarTargetArray(int position, int size) {
        double[] result = new double[size];
        for (int i = 0; i < size; i++) {
            result[i] = -1;
        }
        result[position] = 1;
        return result;
    }
    
    public static double[] flattenIntMatrix(int[][] ImageMatrix){
        int h = ImageMatrix.length;
        int w = ImageMatrix[0].length;
        double[] result = new double[w*h];
        for (int i=0;i<h;i++){
            for (int j=0;j<w;j++){
                result[i*w+j]=ImageMatrix[i][j];
            }
        }
        return result;
    }
    
    public static double[] normalizeArray(double[] input){
        int l = input.length;
        double[] result = new double[l];
        for (int i=0;i<l;i++){
            if (input[i]>=1){
                result[i]=1;
            } else {
                result[i]=-1;
            }
        }
        return result;
    }
    
    public static int getPositionFromResult(double[] output){
    	int result=0;
    	for (int i=0;i<output.length;i++){
    		if (output[i]==1){
    			result=i;
    			break;
    		}
    	}
    	return result;
    }
}
